package com.example.algorithm_learning_platform.controller;

import com.example.algorithm_learning_platform.common.Result;
import com.example.algorithm_learning_platform.dto.ChatRequest;
import com.example.algorithm_learning_platform.entity.ChatMessage;
import com.example.algorithm_learning_platform.service.ChatService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "AI问答", description = "处理用户与AI的对话")
@RestController
@RequestMapping("/api/chat")
@RequiredArgsConstructor
public class ChatController {

    private final ChatService chatService;

    @Operation(summary = "发送问题获取AI回答")
    @PostMapping
    public Result<ChatMessage> chat(@RequestBody ChatRequest request) {
        ChatMessage response = chatService.chat(request.getQuestion(), request.getUserId());
        return Result.success(response);
    }
} 